import java.io.IOException;

import org.apache.solr.client.solrj.SolrServer;  
import org.apache.solr.client.solrj.impl.HttpSolrServer;  
import org.apache.solr.common.SolrInputDocument;


/**
 * 提交索引
 * @author maguoqing
 *
 */
public class Test1 {

	public static void main(String[] args) {
		
		 try {
			String serverUrl = (args != null && args.length > 0) ? args[0]  
			            : "http://localhost:8080/solr/collection1";  
			      
			    SolrServer solrServer = new HttpSolrServer(serverUrl);  
			      
			    SolrInputDocument doc1 = new SolrInputDocument();  
			    doc1.setField("id", "4");  
			    doc1.setField("title", "http://www.163.com/");  
			    solrServer.add(doc1);  
			      
			    SolrInputDocument doc2 = new SolrInputDocument();  
			    doc2.setField("id", "5");  
			    doc2.setField("title", "http://www.sina.com/");  
			    solrServer.add(doc2);  
			      
			    solrServer.commit(true,true);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
